// TestHiveManager.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include "../HiveManager/HiveManager.h"
#pragma comment(lib, "../OfflineReg/offreg.lib")
#pragma comment(lib,"../Release/HiveManager.lib")
#pragma comment(lib, "advapi32.lib")
int _tmain(int argc, _TCHAR* argv[])
{
	//HKEY hReg;
	DWORD ret;
	//ChangeKeyName(L"ZZZZZZNishiD");


	//DWORD ret = UnLoadHiveInt(0,L"apphive");
	//printf("%d\n",ret);
	/*
	HKEY hReg;
	DWORD ret;
	//ret = RegOpenKey(HKEY_LOCAL_MACHINE,L"SOFTWARE",&hReg);

	LPWSTR lpszUni = L"\\REGISTRY\\USER\\S-1-5-21-4188974329-886920603-2178218778-500_Classes";
	
	hReg = HKEY_LOCAL_MACHINE;
	//ret = ChangeKeyName(hReg,L"aloha");
	printf("%d",(lstrlen(lpszUni))* sizeof(WCHAR));
	ret = LinkReg(hReg,L"SOFTWARE\\test09",( const BYTE* )lpszUni,(lstrlen(lpszUni))* sizeof(WCHAR));

	//ret = UnLinkReg(hReg,L"test04");

	LPSTR lpBuffer;
	::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM  ,NULL,ret,LANG_USER_DEFAULT,(LPTSTR) & lpBuffer,0,NULL);
	::MessageBox(NULL,(LPCWSTR)lpBuffer,L"Info",0);
	LocalFree(lpBuffer);
	*/
	//LPWSTR lpszUni = L"\\REGISTRY\\USER\\jjj\\MACHINE";
	//hReg = HKEY_LOCAL_MACHINE;
	//ret = ChangeKeyName(hReg,L"aloha");
	//printf("%d",(lstrlen(lpszUni))* sizeof(WCHAR));
	//ret = LinkReg(HKEY_CURRENT_USER,L"SOFTWARE\\test03",( const BYTE* )lpszUni,(lstrlen(lpszUni))* sizeof(WCHAR));

	//LPWSTR uni = L"\\REGISTRY\\USER\\jjj";
	//printf("len = %d",(lstrlen(uni))* sizeof(WCHAR));
	//ret = LinkReg(HKEY_CURRENT_USER,L"REG",( const BYTE* )(uni),(lstrlen(uni))* sizeof(WCHAR));
	//printf("ret = %d\n",ret);
	printf("start\n");
	HKEY hkResult;
	LoadHiveInt(0,L"Test",L"E:\\TAR.dat");
	LPWSTR lpszUni = L"\\REGISTRY\\USER\\Test";
	LinkReg(HKEY_CURRENT_USER,L"REG\\00\\Hello",(const BYTE *)lpszUni,(lstrlen(lpszUni)*sizeof(WCHAR)));
	UnLoadHiveInt(0,L"Test");
	//ret = RegOpenKey(HKEY_CURRENT_USER,L"REG\\00\\Hello",&hkResult);
	//if( ret == 2 )
	//{
		UnLinkReg(HKEY_CURRENT_USER,L"REG\\00\\Hello");
	//}
	printf("Open reg return code = %d\n",ret);
	PreCheckReg();
	system("Pause");
	return 0;
}

